import jsonp from 'common/js/jsonp';
import { commonParams, options } from './config';
import axios from 'axios';

const debug = process.env.NODE_ENV !== 'production';

export function getRecommend() {
  const url =
    'https://c.y.qq.com/musichall/fcgi-bin/fcg_yqqhomepagerecommend.fcg';
  const data = Object.assign({}, commonParams, {
    platform: 'h5',
    // 请求来源h5平台
    uin: 0,
    // uin是qq号，默认为0不登录
    needNewCode: 1
  });

  return jsonp(url, data, options);
  // 返回的是一个promise
}

export function getDiscList() {
  // 线上环境地址，同学们根据自己的需要配置修改
  const url = debug
    ? '/api/getDiscList'
    : 'http://ustbhuangyi.com/music/api/getDiscList';

  const data = Object.assign({}, commonParams, {
    platform: 'yqq',
    hostUin: 0,
    sin: 0,
    ein: 29,
    sortId: 5,
    needNewCode: 0,
    categoryId: 10000000,
    rnd: Math.random(),
    format: 'json'
  });

  return axios
    .get(url, {
      params: data
    })
    .then(res => {
      return Promise.resolve(res.data);
    });
}

export function getSongList(disstid) {
  // 线上环境地址，同学们根据自己的需要配置修改
  const url = debug
    ? '/api/getCdInfo'
    : 'http://ustbhuangyi.com/music/api/getCdInfo';

  const data = Object.assign({}, commonParams, {
    disstid,
    type: 1,
    json: 1,
    utf8: 1,
    onlysong: 0,
    platform: 'yqq',
    hostUin: 0,
    needNewCode: 0
  });

  return axios
    .get(url, {
      params: data
    })
    .then(res => {
      return Promise.resolve(res.data);
    });
}
